package juniors.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import juniors.modelo.Idea;
import juniors.negocio.GestionIdeas;

/**
 * Servlet implementation class IdeaEditarServlet
 */
@WebServlet("/IdeaEditarServlet")
public class IdeaEditarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdeaEditarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try {
			//Obtiene el Codigo de la Idea
			int idIdea = Integer.parseInt(request.getParameter("id"));
			
			//Obtiene la Idea con el codigo recibido
			GestionIdeas negocio = new GestionIdeas();
			
			Idea idea = negocio.obtener(idIdea);
			
			if (idea != null) {
				//Redirecciona a idea_editar pasando como parametro el objeto idea cargado
				RequestDispatcher rd = request.getRequestDispatcher("/idea_editar.jsp");
				request.setAttribute("idea", idea);
				
				rd.forward(request, response);
				
			}
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
